package com.test.util.interceptor;

import com.test.pojo.SystemUser;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;

public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        SystemUser user = (SystemUser) request.getSession().getAttribute("user");
        if(user != null){
            return true;
        }
        response.sendRedirect(request.getContextPath() +"/index.jsp?msg="+ URLEncoder.encode("你还没有登录,请先登录", "UTF-8") );
        return false;
    }
}
